package com.jinsi.controller;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.pojo.*;
import com.jinsi.service.impl.ScPrintServiceImpl;
import com.jinsi.utils.MapReturn;
import com.jinsi.utils.StuIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
public class ScPrintController {

    @Autowired
    private ScPrintServiceImpl service;


    @ResponseBody
    @RequestMapping("/getPrintRecord")
    public Map<String,Object> getPrintRecord(Integer page, Integer limit){
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page,limit);
        List<ScPrintRecord> list = service.getPrintRecord();
        PageInfo<ScPrintRecord> pageInfo = new PageInfo<>(list);
        map.put("total",pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        map.put("state",0);
        map.put("msg","成功");
        return map;
    }

    @ResponseBody
    @RequestMapping("/getPrintRecordByStuName")
    public Map<String,Object> getPrintRecord(Integer page, Integer limit,String studentName){
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page,limit);
        List<ScPrintRecord> list = service.getPrintRecordByStuName(studentName);
        PageInfo<ScPrintRecord> pageInfo = new PageInfo<>(list);
        map.put("total",pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        map.put("state",0);
        map.put("msg","成功");
        return map;
    }

    @ResponseBody
    @RequestMapping("/addPrint")
    public Map<String,String> addPrint(ScPrintRecord record,String idlist){
        String l = idlist;
        record.setIslist(l);
        Map<String, String> map = new HashMap<>();
        try {
            record.setRecordRemark(0);
            service.addPrintRecord(record);
            map.put("state","200");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state","400");
        }
        return map;
    }


    @ResponseBody
    @RequestMapping("/getPrint")
    public Map<String,Object> getPrint(ScPrintRecord record){
        service.getIdlist(record.getRecordId());
        Map<String, Object> map = new HashMap<>();
//        ScStudent student = service.getStudent(record.getStudentId());
        List<Map<String,Object>> prints = service.getPrintById(record.getRecordId());
        return MapReturn.getSuccess(prints);
    }


}
